/**
 * JAVACC DEMO 1.0
 * @copy right apache company All rights reserved. 
 * @Package com.apache.rpc.service.impl  
 */
package com.apache.rpc.service.impl;

import java.util.Map;

import org.apache.log4j.Logger;

import com.apache.api.api.ApiService;
import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.database.constant.Validator;
import com.apache.exception.ServiceException;

/**
 * description:  
 * @author Hou Dayu 创建时间：2014-11-4  
 * @Copyright(c)2014:
 */
public class InterfaceRegisterServiceImpl implements ApiService {

	private Map<String, PluginConnector> plugins;
	private Logger log = Logger.getLogger(InterfaceRegisterServiceImpl.class);

	public ResultEntity doService(ParamsVo vo) throws ServiceException {
		ResultEntity result = new ResultEntity();
		result.setResult("false");
		if (Validator.isEmpty(plugins.get(vo.getMethodKey()))) {
			result.setMessage("没有确要执行的方法");
			result.setEntity("T");
		} else {
			try {
				return (ResultEntity) plugins.get(vo.getMethodKey()).execute(vo);
			} catch (Exception e) {
				e.printStackTrace();
				log.error(e);
				throw new ServiceException("执行方法[" + vo.getMethodKey() + "]", e);
			}
		}
		return result;
	}

	public void setPlugins(Map<String, PluginConnector> plugins) {
		this.plugins = plugins;
	}

}
